package util;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ImageUtil {

	public static void resize(String path, String name, int width, int height) {

		Image image = null;
		try {
			image = ImageIO.read(new File(path + name)).getScaledInstance(width, height, Image.SCALE_SMOOTH);

			BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
			bi.createGraphics().drawImage(image, 0, 0, null);

			FileOutputStream fos;

			fos = new FileOutputStream(path + name );
			javax.imageio.ImageIO.write(bi, name.substring(name.length() - 3, name.length()), fos);
			fos.close();

		} catch (IOException ex) {
			ex.printStackTrace();
		}
	}
}
